package com.atguigu.gmall.product.service.impl;
import com.atguigu.entity.BaseAttrInfo;
import com.atguigu.entity.BaseAttrValue;
import com.atguigu.gmall.product.mapper.BaseAttrInfoMapper;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import com.atguigu.gmall.product.service.BaseAttrValueService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * <p>
 * 属性表 服务实现类
 * </p>
 *
 * @author 冇有
 * @since 2021-09-16
 */
@Service
public class BaseAttrInfoServiceImpl extends ServiceImpl<BaseAttrInfoMapper, BaseAttrInfo> implements BaseAttrInfoService {
    /**
     * 根据传递的三个分类id查询平台属性
     * @param category1Id
     * @param category2Id
     * @param category3Id
     * @return 什么错 平台属性 你看下mapper.xml有没有写对
     */
    @Autowired
    BaseAttrInfoMapper baseAttrInfoMapper;
    @Autowired
    BaseAttrValueService baseAttrValueService;
    @Override
    public List<BaseAttrInfo> attrInfoList(Long category1Id, Long category2Id, Long category3Id) {
      List<BaseAttrInfo> baseAttrInfoList =baseAttrInfoMapper.attrInfoList(category1Id,category2Id,category3Id);
        return baseAttrInfoList;
    }
    /**
     * 将传递进来的 baseAttrInfo对象添加到数据库
     * 需要取出其中的平台属性值
     * @param baseAttrInfo
     */
    @Override
    public void saveAttrInfo(BaseAttrInfo baseAttrInfo) {
         baseAttrInfoMapper.insert(baseAttrInfo);
        List<BaseAttrValue> attrValues = baseAttrInfo.getAttrValueList();
        for (BaseAttrValue baseAttrValue:attrValues
             ) {
            //传递过来的attrValues是没有外键信息的
            baseAttrValue.setAttrId(baseAttrInfo.getId());
            baseAttrValueService.save(baseAttrValue);
        }
    }
}
